<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<jsp:useBean id="user" class="model.User" scope="session" />
<jsp:useBean id="mfromTown" class="model.Mesto" scope="session" />
<jsp:useBean id="mToTown" class="model.Mesto" scope="session" />
<jsp:useBean id="putnaDuz" class="model.PutnaDuz" scope="session" />

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Izmena linije</title>

<script language="javascript" src="js/prototype-1.6.0.2.js"></script>
<script language="javascript" src="js/prototype-base-extensions.js"></script>
<script language="javascript" src="js/prototype-date-extensions.js"></script>
<script language="javascript" src="js/datepicker.js"></script>
<link rel="stylesheet" href="css/datepicker.css" />

</head>
<body>
<%
	if (user != null && user.isLoggedIn() || !user.isAdmin()) {
%>
<form action="/admin" method=post>
<table>
	<tr>
		<td align="right">Start:</td>
		<td><select name="fromTown">
			<c:forEach var="town" items="${sessionScope.allTowns}">
				<c:set var="toTownID">${town.sifra.id}</c:set>
				<%
					if (mfromTown.getSifra() == null) {
				%>
				<option>${town.naziv}</option>
				<%
					} else {

								long ID1 = Long.parseLong(pageContext
										.getAttribute("toTownID") + "");
								long ID2 = mfromTown.getSifra().getId();

								if (ID1 != ID2) {
				%>
				<option>${town.naziv}</option>
				<%
					} else {
				%>
				<option selected="selected">${town.naziv}</option>
				<%
					}
				%>
				<%
					}
				%>
			</c:forEach>
		</select></td>
	</tr>
	<tr>
		<td align="right">Cilj:</td>
		<td><select name="toTown">
			<c:forEach var="town" items="${sessionScope.allTowns}">
				<c:set var="toTownID">${town.sifra.id}</c:set>
				<%
					if (mToTown.getSifra() == null) {
				%>
				<option>${town.naziv}</option>
				<%
					} else {

								long ID1 = Long.parseLong(pageContext
										.getAttribute("toTownID") + "");
								long ID2 = mToTown.getSifra().getId();

								if (ID1 != ID2) {
				%>
				<option>${town.naziv}</option>
				<%
					} else {
				%>
				<option selected="selected">${town.naziv}</option>
				<%
					}
				%>
				<%
					}
				%>
			</c:forEach>
		</select></td>
	</tr>
	<tr>
		<td align=right>Cena:</td>
		<td><input type="text" name="cena" value="${putnaDuz.cena}"
			size="10" maxlength="7">din.</td>
	</tr>
	<tr>
		<c:set var="polazak">
			<fmt:formatDate pattern="hh:mm" value="${putnaDuz.polazak}" />
		</c:set>

		<td align=right>Polazak:<br>
		<small>(satnica)</small></td>
		<td><input type="text" id="my_datepicker" name="polazak"
			value="${polazak}" size="5" class="timepicker" /></td>
	</tr>
	<tr>
		<c:set var="dolazak">
			<fmt:formatDate pattern="hh:mm" value="${putnaDuz.dolazak}" />
		</c:set>
		<td align=right>Dolazak:<br>
		<small>(satnica)</small></td>
		<td><input type="text" id="my_datepicker2" name="dolazak"
			value="${dolazak}" size="5" class="timepicker" /></td>
	</tr>
	<tr>
		<td align="right">Povlastice:<br />
		<small>(drzite CTRL za vise)</small></td>
		<td><select name="bens" multiple="multiple" size="5">
			<c:forEach var="ben" items="${putnaDuz.povlastica}">
				<c:set var="benID">${ben.sifra.id}</c:set>
				<c:out value="${ben.sifra.id}"></c:out>
				<c:forEach var="readedBen" items="${sessionScope.allBens}">
					<c:set var="rBenID">${readedBen.sifra.id}</c:set>
					<c:out value="${readedBen.sifra.id}"></c:out>
					<%
						String ID1 = (String) pageContext.getAttribute("benID");
									String ID2 = pageContext.getAttribute("rBenID") + "";

									if (!ID1.equals(ID2)) {
					%>
					<option value="${ben.sifra.id}">${ben.naziv}</option>
					<%
						} else {
					%>
					<option selected="selected" value="${ben.sifra.id}">${ben.naziv}</option>
					<%
						}
					%>
				</c:forEach>
			</c:forEach>
		</select></td>
	</tr>

	<tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td><input type="hidden" name="ID" value="${putnaDuz.sifra.id}">
		<input type="hidden" name="changedTrip" value="true"></td>
		<td><input type="submit" value="Izmeni" /></td>
	</tr>
</table>
</form>

<script language="javascript">
	new Control.DatePicker('my_datepicker', {
		icon : 'images/clock.png',
		timePicker : true,
		datePicker : false,
		use24hrs : true,
		timePickerAdjacent : true
	});
</script>
<script>
	new Control.DatePicker('my_datepicker2', {
		icon : 'images/clock.png',
		timePicker : true,
		datePicker : false,
		use24hrs : true,
		timePickerAdjacent : true
	});
</script>
<%
	} else {
%>

<p>Niste se prijavili! <br>
<a href="/logIn">Logovanje</a></p>

<%
	}
%>

<p><a href="/admin">Red voznje</a> <br>
<a href="/logIn?logOff=true">Odjava</a></p>

</body>
</html>